package com.antdesignbackend.backend.common;

import java.util.Random;

/**
 * Created by Administrator on 2020/2/29.
 */
public class ClassHelper {
    /*
    将数字转成中文
     */
    public static String numberToChinese(int number) {
        String[] numbers = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
        String[] units = {"", "十", "百", "千", "万", "十", "百", "千", "亿", "十"};
        String sign = number < 0 ? "负" : "";
        if (number < 0) {
            number = -number;
        }
        StringBuilder result = new StringBuilder(sign);
        String string = String.valueOf(number);
        int n = string.length();
        char[] numberCharArray = string.toCharArray();
        for (int i = 0; i < n; i++) {
            int digNum = n - i; // 位数
            int num = numberCharArray[i] - '0';
            if (num != 0) {
                result.append(numbers[num]).append(units[digNum - 1]);
                continue;
            }

            if (result.toString().endsWith(numbers[0])) {
                // 如果是单位所在的位数，则去除上一个0，加上单位
                if (digNum % 4 == 1) {
                    result.deleteCharAt(result.length() - 1);
                    result.append(units[digNum - 1]);
                }
            }else{
                result.append(numbers[0]);
            }
        }
        return result.toString();
    }
    /*
  1-7将数字转成中文的周一到周日
   */
    public static String WeekStr(int number) {
        String result ="";
   switch (number)
   {
       case 1:
           result="一";
           break;
       case 2:
           result="二";
           break;
       case 3:
           result="三";
           break;
       case 4:
           result="四";
           break;
       case 5:
           result="五";
           break;
       case 6:
           result="六";
           break;
       case 7:
           result="日";
           break;
       default:
    break;
   }
        return result;
    }
    //length用户要求产生字符串的长度
    public static String getRandomString(int length){
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
}
